/// <reference path="../vsdoc/jquery-1.8.3-vsdoc.js" />
/** TreeView **/

$(document).ready(function ()
{
    $("MENU.treeView UL LI *").live('click', function (e)
    {
        e.stopPropagation(); // remove the LI clicks
    });
    $("MENU.treeView UL LI.ed").live('click', function (e)
    {
        $(this).removeClass("ed");
        $(this).addClass("cd");
        $("UL", this).first().hide();
        alterImage(this);
        processNode(this);
        return false;
    });
    $("MENU.treeView UL LI.cd").live('click', function (e)
    {
        $(this).removeClass("cd");
        $(this).addClass("ed");
        alterImage(this);
        var child = $("UL", this).first();
        if (child.length == 1)
        {
            child.show();
            processNode(this)
        }
        else
        {
            processNode(this, true);
        }
        return false;
    });
});
function alterImage(target)
{
    var image = $("IMG", target).first();

    if (image.length != 1)
    {
        return false;
    }

    var newPath = image.data("alter");
    image.data("alter", image.attr("src"));
    image.attr("src", newPath);
}
function processNode(target, process)
{
    var parent = $(target).parents("MENU.treeView").first();
    var url = parent.data("nodeurl");
    url += url.indexOf("?") >= 0 ? "&" : "?";
    url += "TvClientID=" + parent.data("tvclientid")
        + "&NodeID=" + $(target).data("nodeid")
        + "&tc=" + new Date().getTime();
    $.get(url, function (result)
    {
        if (process)
        {
            $(target).append(result);
        }
    });
}